package com.xiaoy.core.base.menu.action;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Results;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.xiaoy.core.base.menu.entity.Menu;
import com.xiaoy.core.base.menu.service.MenuService;
import com.xiaoy.page.PageEasy;
import com.xiaoy.web.BasicAction;
@Namespace("/base/menu")
@Results( {
})
public class MenuAction extends BasicAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource(name="menuService")
	private MenuService service;
	
	public String list () {
		
		PageEasy<Menu> page = new PageEasy<Menu>();
		InitPageWrapper(page);
		service.filterPage(page);
		
//		for (Menu m : page.getResult()) {
//			System.out.println(m.getId()+"-"+m.getName());
//		}
		
		request.setAttribute("pageBean", page);
		
		
		String p = toJson(page);
//		System.out.println(p);
		
		request.setAttribute("page", p);
		return "list";
	}
	
	public void list2 () {
		
		PageEasy<Menu> page = new PageEasy<Menu>();
		InitPageWrapper(page);
		service.filterPage(page);
		
//		for (Menu m : page.getResult()) {
//			System.out.println(m.getId()+"-"+m.getName());
//		}
		
		String p = toJson(page);
//		System.out.println(p);
		
		Struts2Utils.renderJson(p);
	}
	
	public String add () {
		
		
		return "add";
	}
	
	public String save () {
		
		service.save(bean);
		return "save";
	}
	
	private Menu bean;

	public Menu getBean() {
		return bean;
	}

	public void setBean(Menu bean) {
		this.bean = bean;
	}


	
	
	
}
